﻿using MyHospital.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyHospital.BLL
{
   public class Doctor
    {
        MyHospitalDataContext db = new MyHospitalDataContext();
        public void deleteDoctor(string id)//删除医生
        {
            DAL.Doctor doctor = (from c in db.Doctor
                             where c.doctorId == int.Parse(id)
                                 select c).FirstOrDefault();
            if (doctor != null)
            {
                db.Doctor.DeleteOnSubmit(doctor);
                db.SubmitChanges();
            }
        }
        public void insertDoctor(string name, string departName, string age, string sex, string phone, string job, string introduce, string image)
        {
            DAL.Doctor doctor = new DAL.Doctor();
            doctor.departId = int.Parse(departName);
            doctor.doctorName = name;
            doctor.age = age;
            doctor.sex = sex;
            doctor.phone = phone;
            doctor.job = job;
            doctor.introduce = introduce;
            doctor.image = image;
            db.Doctor.InsertOnSubmit(doctor);
            db.SubmitChanges();
        }
        public string getDoctorName(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                             where c.doctorId == id
                             select c).FirstOrDefault();
            return doctor.doctorName;
        }
        public string getDoctorAge(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.age;
        }
        public string getDoctorPhone(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.phone;
        }
        public string getDoctorJob(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.job;
        }
        public string getDoctorIntroduce(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.introduce;
        }
        public string getDoctorImage(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.image;
        }
        public int getDoctorDepart(int id)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            return doctor.departId;
        }
        public void updateDoctor(int id,string name, string departName, string age, string sex, string phone, string job, string introduce, string image)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorId == id
                                 select c).FirstOrDefault();
            doctor.departId = int.Parse(departName);
            doctor.doctorName = name;
            doctor.age = age;
            doctor.sex = sex;
            doctor.phone = phone;
            doctor.job = job;
            doctor.introduce = introduce;
            doctor.image = image;
            db.SubmitChanges();
        }
        public bool isDoctorExit(string name)
        {
            DAL.Doctor doctor = (from c in db.Doctor
                                 where c.doctorName == name
                                 select c).FirstOrDefault();
            if (doctor != null) return true;
            else return false;
        }
        public IQueryable<DAL.Doctor> GetDoctorsList(string name)//模糊查找
        {
            var result = from c in db.Doctor
                         where System.Data.Linq.SqlClient.SqlMethods.Like(c.doctorName, ("%" + name + "%"))
                         select c;
            return result;
        }
    }

}
